using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Toenda.Rails.System;
using Toenda.Rails.DataContainer;

public partial class Controls_ctrl_topmenu : System.Web.UI.UserControl {
	private AccountProvider ap = new AccountProvider();

	/// <summary>
	/// Page_Load
	/// </summary>
	/// <param name="sender"></param>
	/// <param name="e"></param>
	protected void Page_Load(object sender, EventArgs e) {
		string id = "";
		Account acc = new Account();

		if(Request.QueryString.Get("id") != null) {
			id = Request.QueryString.Get("id").ToString();
		}

		if(!IsPostBack) {
			if(Session.Count > 0 
			&& ap.CheckSessionExist(Session["Zappr"].ToString())) {
				acc = ap.GetAccountBySession(Session["Zappr"].ToString());

				//mnuMain.Items[0].NavigateUrl = "~/default.aspx?id=images&user=" + acc.Username;
				//mnuMain.Items[0].ChildItems[0].NavigateUrl = "~/default.aspx?id=images&user=" + acc.Username;
				//mnuMain.Items[0].ChildItems[1].NavigateUrl = "~/default.aspx?id=sets&user=" + acc.Username;
				mnuMain.Items[0].NavigateUrl = "~/images/" + acc.Username + "/default.aspx";
				mnuMain.Items[0].ChildItems[0].NavigateUrl = "~/images/" + acc.Username + "/default.aspx";
				mnuMain.Items[0].ChildItems[1].NavigateUrl = "~/sets/" + acc.Username + "/default.aspx";

				mnuMain.Items[1].ChildItems[1].NavigateUrl = "~/user/" + acc.Username + "/default.aspx";

				//if(acc.Type == 0 && acc.UpgradeIsInWork == false) {
				//    if(mnuMain.Items[1].ChildItems.Count > 2) {
				//        mnuMain.Items[1].ChildItems.RemoveAt(2);
				//    }

				//    MenuItem itemUpgrade = new MenuItem();
				//    itemUpgrade.Text = GetLocalResourceObject("Upgrade").ToString();
				//    itemUpgrade.NavigateUrl = "~/upgrade/default.aspx";

				//    mnuMain.Items[1].ChildItems.AddAt(2, itemUpgrade);
				//}

				if(acc.Type == 2) {
					mnuMain.Items[1].ChildItems[1].SeparatorImageUrl = "~/App_Themes/Default/Images/Seperator.jpg";

					MenuItem itemDelUser = new MenuItem();
					itemDelUser.Text = GetLocalResourceObject("User").ToString();
					itemDelUser.NavigateUrl = "~/default.aspx?id=_deleteuser";

					mnuMain.Items[1].ChildItems.Add(itemDelUser);

					MenuItem itemDelImage = new MenuItem();
					itemDelImage.Text = GetLocalResourceObject("Images").ToString();
					itemDelImage.NavigateUrl = "~/default.aspx?id=_deleteimage";

					mnuMain.Items[1].ChildItems.Add(itemDelImage);

					MenuItem itemEnableProAccount = new MenuItem();
					itemEnableProAccount.Text = GetLocalResourceObject("EnableProAccount").ToString();
					itemEnableProAccount.NavigateUrl = "~/default.aspx?id=_enablepro";

					mnuMain.Items[1].ChildItems.Add(itemEnableProAccount);

					MenuItem itemDisableProAccount = new MenuItem();
					itemDisableProAccount.Text = GetLocalResourceObject("DisableProAccount").ToString();
					itemDisableProAccount.NavigateUrl = "~/default.aspx?id=_enablepro&search=enabled";

					mnuMain.Items[1].ChildItems.Add(itemDisableProAccount);

					MenuItem itemSetProAccountExpiresDate = new MenuItem();
					itemSetProAccountExpiresDate.Text = GetLocalResourceObject("SetProAccountExpiresDate").ToString();
					itemSetProAccountExpiresDate.NavigateUrl = "~/default.aspx?id=_setproexpiredate";

					mnuMain.Items[1].ChildItems.Add(itemSetProAccountExpiresDate);
				}
			}
		}

		switch(id) {
			//case "Dashboard":
			case "images":
			case "sets":
			case "upload":
				mnuMain.Items[0].Selected = true;
				mnuMain.Items[0].Selectable = false;
				break;

			case "account":
			case "profile":
				mnuMain.Items[1].Selected = true;
				mnuMain.Items[1].Selectable = false;
				break;

			default:
				//mnuMain.Items[0].Selected = true;
				//mnuMain.Items[0].Selectable = false;
				break;
		}
	}
}
